package com.hhf.rpc.core.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;
import com.hhf.rpc.core.config.RpcConfig;

/**
 * @Author hhf
 * @Date 2024/10/16
 * @Description rpc配置工具类
 */
public class RpcConfigUtil {


    public static <T> T loadRpcConfig(Class<T> clazz,String prefix){
        return loadRpcConfig(clazz,prefix,"");
    }

    public static <T> T loadRpcConfig(Class<T> clazz,String prefix,String environment){
        StringBuilder rpcConfigStringBuilder = new StringBuilder("application");
        if (StrUtil.isNotBlank(environment)){
            rpcConfigStringBuilder.append("-").append(environment);
        }
        rpcConfigStringBuilder.append(".properties");
        Props props = new Props(rpcConfigStringBuilder.toString());
        return props.toBean(clazz, prefix);
    }


}
